package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Classinfo;
import cn.wolfcode.crm.mapper.ClassinfoMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IClassinfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassinfoServiceImpl implements IClassinfoService {
    @Autowired
    private ClassinfoMapper classinfoMapper;


    @Override
    public void delete(Long id) {

        classinfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void save(Classinfo classinfo) {
        classinfoMapper.insert(classinfo);

    }

    @Override
    public Classinfo get(Long id) {

        return classinfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Classinfo> listAll() {
        return classinfoMapper.selectAll();
    }

    @Override
    public void update(Classinfo classinfo) {
        classinfoMapper.updateByPrimaryKey(classinfo);
    }

    /*    @Override
        public PageResult query(QueryObject qo) {
            //查询总数,建立方法selectForCount
            int count = classinfoMapper.selectForCount(qo);
            //判断是否有数据
            if(count==0){
                return new PageResult(qo.getPageSize());
            }
            //如果有数据,就查询,查询结果集,建立查询方法selectForList
            //查询的是执行pageResult构造器中配置的四个选项
            List<Classinfo> list = classinfoMapper.selectForList(qo);
            return new PageResult(qo.getCurrentPage(),count,list,qo.getPageSize());
        }*/
    @Override
    public PageInfo query(QueryObject qo) {
        //对比上面注释的内容
        //使用分页插件,每页显示数量
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        //查询结果集
        List<Classinfo> list = classinfoMapper.selectForList(qo);
        return new PageInfo(list);

    }
}